package com.tinyideatech.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tinyideatech.common.json.JSONObject;
import com.tinyideatech.system.entity.CarOrder;
import com.tinyideatech.system.entity.CarQrcode;
import com.tinyideatech.system.mapper.CarOrderMapper;
import com.tinyideatech.system.mapper.CarQrcodeMapper;
import com.tinyideatech.system.service.ICarQrcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangy-5
 * @date 2019-09-09
 */
@Service
public class CarQrcodeServiceImpl extends ServiceImpl<CarQrcodeMapper, CarQrcode> implements ICarQrcodeService {

    @Autowired
    private CarOrderMapper carOrderMapper;

    @Autowired
    private CarQrcodeMapper carQrcodeMapper;

    @Override
    public void changeStatus(CarQrcode carQrcode) {


    }

    @Override
    public JSONObject alreadyOrder(String deviceId, Integer feature) {
        List<CarOrder> carOrder = carOrderMapper.selectList(
                new QueryWrapper<CarOrder>().eq("device_id", deviceId)
                        .eq("feature", feature)
                        .isNull("transaction_id"));
        String url = carQrcodeMapper.selectAllByDeviceName(deviceId).getQrcodeUrl();
        JSONObject result = new JSONObject();
        result.put("url", url);
        result.put("prepayId", carOrder.get(0).getPrepayId());
        return result;
    }

}
